package br.edu.ufcg.symbolrt.examples;

import br.edu.ufcg.symbolrt.base.Action;
import br.edu.ufcg.symbolrt.base.ClockGuard;
import br.edu.ufcg.symbolrt.base.Location;
import br.edu.ufcg.symbolrt.base.SimpleClockGuard;
import br.edu.ufcg.symbolrt.base.TIOSTS;
import br.edu.ufcg.symbolrt.base.TypedData;
import br.edu.ufcg.symbolrt.util.Constants;

public class TargetTracking {
	
	 public static TIOSTS createSPEC(){
		 TIOSTS tiosts = new TIOSTS("Target Tracking");
		 
		 // Clocks and their guards
		 
		 tiosts.addClock("clock2");	
         SimpleClockGuard guard1 = new SimpleClockGuard(4, "clock2", Constants.GUARD_EQUAL, "40");
 		 ClockGuard clockGuard1 = new ClockGuard();
 	     clockGuard1.addSimpleClockGuard(guard1); 		 	 
		 
         // Variables
         TypedData modeTT = new TypedData("modeTT", Constants.TYPE_INTEGER);
         tiosts.addVariable(modeTT);
         TypedData rangeTT = new TypedData("rangeTT", Constants.TYPE_INTEGER);
         tiosts.addVariable(rangeTT);
         TypedData azimuthTT = new TypedData("azimuthTT", Constants.TYPE_INTEGER);
         tiosts.addVariable(azimuthTT);
         TypedData elevationTT = new TypedData("elevationTT", Constants.TYPE_INTEGER);
         tiosts.addVariable(elevationTT);
         
         // Parameters
         TypedData op = new TypedData("op", Constants.TYPE_INTEGER);
         tiosts.addActionParameter(op);
         TypedData r = new TypedData("r", Constants.TYPE_INTEGER);
         tiosts.addActionParameter(r);
         TypedData a = new TypedData("a", Constants.TYPE_INTEGER);
         tiosts.addActionParameter(a);
         TypedData e = new TypedData("e", Constants.TYPE_INTEGER);
         tiosts.addActionParameter(e);
         
         // Input, output, and internal actions

         Action init = new Action("init2", Constants.ACTION_INTERNAL);
         tiosts.addAction(init);

         Action finishTargetDesignation = new Action("finishTargetDesignation", Constants.ACTION_INPUT);
         finishTargetDesignation.addParameter(op.getName());
         tiosts.addAction(finishTargetDesignation);
         
         Action changeModeRadar = new Action("changeModeRadar", Constants.ACTION_OUTPUT);
         tiosts.addAction(changeModeRadar);
         
         Action aircraftPosition = new Action("aircraftPosition", Constants.ACTION_INPUT);
         aircraftPosition.addParameter(a.getName());
         aircraftPosition.addParameter(e.getName());
         aircraftPosition.addParameter(r.getName());
         tiosts.addAction(aircraftPosition);   
         
         Action targetPositionOut = new Action("targetPosition", Constants.ACTION_OUTPUT);
         targetPositionOut.addParameter(a.getName());
         targetPositionOut.addParameter(e.getName());
         targetPositionOut.addParameter(r.getName());
         tiosts.addAction(targetPositionOut);
         
         Action reticlePositionHotasIn = new Action("reticlePositionHotas", Constants.ACTION_INPUT);
         reticlePositionHotasIn.addParameter(a.getName());
         reticlePositionHotasIn.addParameter(e.getName());
         reticlePositionHotasIn.addParameter(r.getName());
         tiosts.addAction(reticlePositionHotasIn);
         
         Action changeModeHUD = new Action("changeModeHUD", Constants.ACTION_OUTPUT);
         tiosts.addAction(changeModeHUD);
         
         Action reticlePositionHUDOut = new Action("reticlePositionHUD", Constants.ACTION_OUTPUT);
         reticlePositionHUDOut.addParameter(r.getName());
         reticlePositionHUDOut.addParameter(a.getName());
         reticlePositionHUDOut.addParameter(e.getName());
         tiosts.addAction(reticlePositionHUDOut);
         
         Action update = new Action("update", Constants.ACTION_OUTPUT);
         update.addParameter(r.getName());
         update.addParameter(a.getName());
         update.addParameter(e.getName());
         tiosts.addAction(update);
         
         Action finishTargetTracking = new Action("finishTargetTracking", Constants.ACTION_OUTPUT);
         finishTargetTracking.addParameter(op.getName());
         tiosts.addAction(finishTargetTracking);      
                           
         // Locations
         Location start = new Location("Start2");
         tiosts.addLocation(start);
         Location S21 = new Location("S21");
         tiosts.addLocation(S21);
         Location S22 = new Location("S22");
         tiosts.addLocation(S22);
         Location S23 = new Location("S23");
         tiosts.addLocation(S23);
         Location S24 = new Location("S24");
         tiosts.addLocation(S24);
         Location S25 = new Location("S25");
         tiosts.addLocation(S25);
         Location S26 = new Location("S26");
         tiosts.addLocation(S26);
         Location S27 = new Location("S27");
         tiosts.addLocation(S27);
         Location S28 = new Location("S28");
         tiosts.addLocation(S28);
         Location S29 = new Location("S29");
         tiosts.addLocation(S29);
         
         // Initial Condition
         tiosts.setInitialCondition(Constants.GUARD_TRUE);
         
         // Initial Location
         tiosts.setInitialLocation(start);
         
         // Transitions
         tiosts.createTransition("Start2", Constants.GUARD_TRUE, Constants.GUARD_TRUE, init, null, null, "S21");
         tiosts.createTransition("S21", Constants.GUARD_TRUE, Constants.GUARD_TRUE, finishTargetDesignation, "modeTT := op", "clock2 := 0", "S22");
         //radarDesignation assumes 3
         tiosts.createTransition("S22", "modeTT = 3", Constants.GUARD_TRUE, changeModeRadar, null, null, "S23");
         tiosts.createTransition("S23", Constants.GUARD_TRUE, Constants.GUARD_TRUE, aircraftPosition, "rangeTT := r| azimuthTT := az| elevationTT := e", null, "S24");
         tiosts.createTransition("S24", Constants.GUARD_TRUE, "rangeTT = r AND azimuthTT = az AND elevationTT = e", targetPositionOut, null, null, "S26");
         //HUDDesignation assumes 2
         tiosts.createTransition("S22", "modeTT = 2", Constants.GUARD_TRUE, changeModeHUD, null, null, "S25");
         tiosts.createTransition("S25", Constants.GUARD_TRUE, Constants.GUARD_TRUE, reticlePositionHotasIn, "azimuthTT := a| elevationTT := e| range := r", null, "S26");
         tiosts.createTransition("S26", "rangeTT = r AND azimuthTT = a AND elevationTT = e", Constants.GUARD_TRUE, reticlePositionHUDOut, null, null, "S27");
         tiosts.createTransition("S27", "rangeTT = r AND azimuthTT = a AND elevationTT = e", clockGuard1, update, null, null, "S28");
         tiosts.createTransition("S28", "modeTT = op", Constants.GUARD_TRUE, finishTargetTracking, null, null, "S29");

         return tiosts;
	 }

}
